<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$return['params']=$params=array('uniacid'=>$_SESSION['uniacid'],);
	if(isset($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if($_RQ['pid']){
		$params['pid']=intval($_RQ['pid']);
		$return['params']['pid']=$_RQ['pid'];
	}
	if(isset($_RQ['type'])){
		$params['type']=intval($_RQ['type']);
		$return['params']['type']=$_RQ['type'];
	}
	if($_RQ['channel']){
		$params['channel']=intval($_RQ['channel']);
		$return['params']['channel']=$_RQ['channel'];
	}
	if($_RQ['create_time']){
		$time_range=cfc('tools')->base64_decode($_RQ['create_time'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['create_time']=$time_range;
		$params['create_time between']=array($time_range['tstart'],$time_range['tend']);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array();
	$list=pdo_getslice('jy_jdpm_money_log',$params,array($pindex,$psize),$total,$fields,'','create_time desc');
	if($list){
		foreach($list as &$item){
			$item['create_time']=date('Y/m/d H:i:s',$item['create_time']);
			//$item['pname']=pdo_getcolumn('jy_jdpm_auction',array('pid'=>$item['pid']),'pname');
			//$item['pname']=$item['pname']?$item['pname']:'';
			$item['account']=pdo_getcolumn('core_members',array('id'=>$item['mid']),'username');
			if($item['mid']<1){
				$item['account']=usercom($item['mid']);
			}
			if(!$item['account']){
				$item['account']=usercom($item['mid']);
			}
		}
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['list']=$list;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'现金记录'),
		),
		'export'=>'export',
		'export_title'=>'导出现金日志',
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'mid','title'=>'用户uid','type'=>'string'),
			array('name'=>'account','title'=>'用户账号','type'=>'string'),
			array('name'=>'pid','title'=>'拍卖PID','type'=>'string'),
			array('name'=>'money','title'=>'金额','type'=>'string'),
			//array('name'=>'order_no','title'=>'充值订单号','type'=>'string'),
			array('name'=>'create_time','title'=>'变动时间','type'=>'string'),
			array('name'=>'type','title'=>'类型','type'=>'radio','options'=>'type'),
			array('name'=>'channel','title'=>'渠道','type'=>'radio','options'=>'channel'),
			array('name'=>'remarks','title'=>'备注','type'=>'string'),
		),
		
		),
		'search'=>array(
			array('type'=>'string','width'=>'10','title'=>'用户UID','name'=>'mid','help'=>''),
			array('type'=>'string','width'=>'10','title'=>'拍品PID','name'=>'pid','help'=>''),
			array('type'=>'select','width'=>'10','title'=>'类型','name'=>'type','options'=>'type2','select_title'=>'请选择类型'),
			array('type'=>'select','width'=>'10','title'=>'渠道','name'=>'channel','help'=>'','options'=>'channel2','select_title'=>'请选择渠道'),
			array('type'=>'time_range','width'=>'16','title'=>'申请时间','name'=>'create_time','help'=>''),
		),
	);
	$return['type']=$this->feetypes();
	$return['channel']=array('1'=>'进账','2'=>'出账');
	$return['type2']=array(
		array('id'=>0,'title'=>'充值/扣除'),
		array('id'=>1,'title'=>'保证金'),
		array('id'=>2,'title'=>'支付订单'),
		array('id'=>3,'title'=>'拍品分享金'),
		array('id'=>4,'title'=>'拍品收入'),
		array('id'=>5,'title'=>'手续费/平台服务费'),
		array('id'=>6,'title'=>'过期订单未支付扣除'),
		array('id'=>7,'title'=>'推广佣金'),
		array('id'=>8,'title'=>'过期订单收取违约金'),
		array('id'=>12,'title'=>'提现冻结'),
		array('id'=>13,'title'=>'提现转出'),
		array('id'=>14,'title'=>'提现解冻'),
		array('id'=>15,'title'=>'支付解冻'),
		array('id'=>16,'title'=>'违约解冻'),
	);
	$return['channel2']=array(array('id'=>1,'title'=>'进账'),array('id'=>2,'title'=>'出账'));
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='export'){
	$params=array('uniacid'=>$_SESSION['uniacid'],);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if($_RQ['type']){
		$params['type']=intval($_RQ['type']);
		$return['params']['type']=$_RQ['type'];
	}
	if($_RQ['channel']){
		$params['channel']=intval($_RQ['channel']);
		$return['params']['channel']=$_RQ['channel'];
	}
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['createtime']=$time_range;
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array();
	$list=pdo_getall('jy_jdpm_money_log',$params,$fields,'','create_time desc');
	if($list){
		$types=$this->feetypes();
		$channels=array('1'=>'进账','2'=>'出账');
		foreach($list as &$item){
			$item['create_time']=date('Y/m/d H:i:s',$item['create_time']);
			$item['pname']=pdo_getcolumn('jy_jdpm_auction',array('pid'=>$item['pid']),'pname');
			$item['account']=pdo_getcolumn('jy_jdpm_member',array('mid'=>$item['mid']),'account');
			if($item['mid']==-1 || $item['mid']==-2){
				$item['account']='平台';
			}
			if(!$item['account']){
				$item['account']='无';
			}
			$item['type']=$types[$item['type']];
			$item['channel']=$channels[$item['channel']];
		}
	}
	$header=array(
		'mid'=>'用户uid',
		'account'=>'用户账号',
		'pname'=>'拍卖名称',
		'money'=>'金额',
		'create_time'=>'变动时间',
		'type'=>'类型',
		'channel'=>'渠道',
		'remark'=>'备注',
	);
	cfc('tools')->export2excel($header,$list,'现金日志');
}